package com.mysterymall.Controller;

import com.mysterymall.Common.Comp.Log;
import com.mysterymall.Common.Utils.Result;
import com.mysterymall.Model.Entity.Address;
import com.mysterymall.Service.AddressService;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName com.mysterymall.Controller
 * @Description
 * @Author HuangWX
 * @Time 2023/12/08  09:52
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    private final AddressService addressService;

    /**
     * 构造器注入
     * @param addressService 地址服务
     */
    public AddressController(AddressService addressService) {
        this.addressService = addressService;
    }

    /**
     * 增加地址
     * @param address 地址信息
     * @return Result
     */
    @PostMapping("/addAddress")
    @Log
    public Result addAddress(@RequestBody Address address){
        return addressService.addAddress(address);
    }

    /**
     * 增加地址
     * @param address 地址信息
     * @return Result
     */
    @PostMapping("/addAddressAdmin")
    @Log
    public Result addAddressAdmin(@RequestBody Address address){
        return addressService.addAddressAdmin(address);
    }

    /**
     * 删除地址
     * @param id 地址id
     * @return Result
     */
    @GetMapping("/deleteAddress")
    @Log
    public Result deleteAddress(@RequestParam("id")String id){
        return addressService.deleteAddress(id);
    }

    /**
     * 修改地址
     * @param address 地址信息
     * @return Result
     */
    @PostMapping("/updateAddress")
    @Log
    public Result updateAddress(@RequestBody Address address){
        return addressService.updateAddress(address);
    }

    /**
     * 修改地址
     * @param address 地址信息
     * @return Result
     */
    @PostMapping("/updateAddressAdmin")
    @Log
    public Result updateAddressAdmin(@RequestBody Address address){
        return addressService.updateAddressAdmin(address);
    }


    /**
     * 查询地址
     * @return Result
     */
    @GetMapping("/queryAddress")
    @Log
    public Result queryAddress(){
        return addressService.queryAddress();
    }

    /**
     * 查询单个地址
     * @return Result
     */
    @GetMapping("/queryOneAddress")
    @Log
    public Result queryOneAddress(@RequestParam("id")String id){
        return addressService.queryOneAddress(id);
    }

    /**
     * 查询单个地址
     * @return Result
     */
    @GetMapping("/queryOneAddressAdmin")
    @Log
    public Result queryOneAddressAdmin(@RequestParam("id")String id){
        return addressService.queryOneAddressAdmin(id);
    }


    @GetMapping("/adminQueryOneAddress")
    @Log
    public Result adminQueryOneAddress(@RequestParam("orderId")String orderId){
        return addressService.adminQueryOneAddress(orderId);
    }
}
